﻿using System.Collections.Generic;
using Game2DFramework;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace MechGame.Utility
{
    class Cursor : GameObject
    {
        private const int CursorSize = 32;

        private static readonly Dictionary<CursorType, Rectangle> RectangleByType = new Dictionary<CursorType, Rectangle>
        {
            { CursorType.Crossbow, new Rectangle(0, 0, CursorSize, CursorSize) },
            { CursorType.Targeting, new Rectangle(CursorSize, 0, CursorSize, CursorSize) },
        };

        private readonly Texture2D _texture;
        private CursorType _type;

        public Vector2 Position { get; private set; }
        public Vector2 WorldPosition { get; private set; }

        public Cursor(Game2D game) : base(game)
        {
            _texture = Game.Content.Load<Texture2D>("Textures/cursors");
            _type = CursorType.Crossbow;
        }

        public virtual void Update()
        {
            Position = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);
            WorldPosition = Position + Game.Camera.Offset;
            _type = CursorType.Crossbow;
        }

        public void SetType(CursorType cursorType)
        {
            _type = cursorType;
        }

        public void Draw()
        {
            Game.SpriteBatch.Draw(_texture, Position, RectangleByType[_type], Color.White, 0.0f, new Vector2(CursorSize) * 0.5f, 1.0f, SpriteEffects.None, 0);
        }
    }
}
